<?php

namespace App\Service;

use App\Models\Area as Areas;

class Area
{
    /**
     * @return mixed
     */
    public function GetProvinceAll()
    {
        return Areas::where('parent_id', '>', 0)->get();
    }

    /**
     * @param $cityId
     * @return mixed
     */
    public function GetcityAll($cityId)
    {
        return Areas::where('parent_id', '=', $cityId)->get();
    }

    /**
     * @param $districtId
     * @return mixed
     */
    public function GetDistrictAll($districtId)
    {
        return Areas::where('parent_id', '=', $districtId)->get();
    }


    public function getAllCitys()
    {
        $pids = (new \App\Models\Area())->where([['parent_id', '=', 1]])->pluck("id");
        $w[] = [function ($query) use ($pids) {
            return $query->whereIn('parent_id', $pids);
        }];
        $city = (new \App\Models\Area())->where($w)->pluck("id");
        $ww[] = [function ($query) use ($city) {
            return $query->whereIn('parent_id', $city);
        }];
        return (new \App\Models\Area())->where($ww)->get();
    }
}
